package com.sugree.thairath.breakingnews;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.util.Log;

public class BreakingNewsReceiver extends BroadcastReceiver {
	public static final String TAG = "BreakingNewsReceiver";

	@Override
	public void onReceive(Context context, Intent intent) {
		PreferenceManager.setDefaultValues(context, R.xml.preferences, false);
		SharedPreferences mSP = PreferenceManager.getDefaultSharedPreferences(context);
		int interval = Integer.parseInt(mSP.getString(BreakingNewsPreference.REFRESH_INTERVAL, "0"));

		Log.d(TAG, "onReceive");
		if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) {
			if (interval > 0) {
				context.startService(new Intent(context, BreakingNewsService.class));
			}
		} else {
			context.startService(new Intent(context, BreakingNewsService.class));
		}
	}
}
